﻿#region

using System;
using System.Linq;
using Elasticsearch.Net;
using Nest;

#endregion

namespace WinFormElasticSearch.EsHelper
{
    /// <summary>
    /// ElasticSearchSource
    /// </summary>
    public class ElasticSearchSource
    {
        /// <summary>
        ///     ElasticSearchSourceConfig
        /// </summary>
        public static ElasticSearchSourceConfig ElasticSearchSourceConfig { get; } = new ElasticSearchSourceConfig();

        /// <summary>
        /// Node
        /// </summary>
        public static Uri[] Node => ElasticSearchSourceConfig.Uris.Select(x => new Uri(x)).ToArray();

        public static ConnectionSettings CreateInstance(string connectionString = null)
        {
            var connectionPool = new SniffingConnectionPool(Node);
            //设置连接
            return new ConnectionSettings(connectionPool)
                .DefaultIndex(ElasticSearchSourceConfig.DefaultIndex);
                //.BasicAuthentication("cloud", "jwellcloud");
        }
    }
}